home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
DDJMAG
/
DDJ9203.ZIP
/
XSHARP.ZIP
/
INITCUBE.C
< prev
next >
Wrap
Text File
|
1992-01-05
|
6KB
|
123 lines
/* Initializes the cubes and adds them to the object list. */
#include <stdlib.h>
#include <math.h>
#include "polygon.h"
#define NUM_CUBES 11 /* # of cubes */
Point3 CubeVerts[NUM_CUBE_VERTS]; /* set elsewhere, from floats */
/* Vertex indices for individual cube faces */
static int Face1[] = {1,3,2,0};
static int Face2[] = {5,7,3,1};
static int Face3[] = {4,5,1,0};
static int Face4[] = {3,7,6,2};
static int Face5[] = {5,4,6,7};
static int Face6[] = {0,2,6,4};
static int *VertNumList[]={Face1, Face2, Face3, Face4, Face5, Face6};
static int VertsInFace[]={ sizeof(Face1)/sizeof(int),
sizeof(Face2)/sizeof(int), sizeof(Face3)/sizeof(int),
sizeof(Face4)/sizeof(int), sizeof(Face5)/sizeof(int),
sizeof(Face6)/sizeof(int) };
/* X, Y, Z rotations for cubes, in tenths of degrees (angles) */
static RotateControl InitialRotate[NUM_CUBES] = {
{0,60,60}, {30,0,30}, {30,30,0},
{-30,20,0},{-60,-30,0},
{30,0,-60},{-20,0,30},{-30,0,-30},
{0,20,-20},{0,-30,30},{0,-60,-60},};
static MoveControl InitialMove[NUM_CUBES] = {
{0,0,75,0,0,-6000,0,0,-350},{0,0,45,0,0,-6000,0,0,-350},
{0,0,50,0,0,-6000,0,0,-350},{0,0,90,0,0,-6000,0,0,-350},
{0,0,60,0,0,-6000,0,0,-350},
{0,0,100,0,0,-6000,0,0,-350},{0,0,70,0,0,-6000,0,0,-350},
{0,0,40,0,0,-6000,0,0,-350},{0,0,80,0,0,-6000,0,0,-350},
{0,0,55,0,0,-6000,0,0,-350},{0,0,65,0,0,-6000,0,0,-350}, };
/* Face colors for various cubes */
static int Colors[NUM_CUBES][NUM_CUBE_FACES] = {
{15,14,12,11,10,9},{1,2,3,4,5,6},{35,37,39,41,43,45},
{47,49,51,53,55,57},{71,73,75,77,79,81},
{83,85,87,89,91,93},{95,97,99,101,103,105},
{107,109,111,113,115,117},{119,121,123,125,127,129},
{131,133,135,137,139,141},{143,145,147,149,151,153} };
/* Starting coordinates for cubes in world space */
static int CubeStartCoords[NUM_CUBES][3] = {
{90,0,-6000}, {90,60,-6000}, {90,-60,-6000}, {30,60,-6000},
{30,-60,-6000}, {-30,0,-6000}, {-30,60,-6000},
{-30,-60,-6000},{-90,0,-6000}, {-90,60,-6000}, {-90,-60,-6000}};
/* Delay counts (speed control) for cubes */
static int InitRDelayCounts[NUM_CUBES] = {1,1,1,1,1,1,1,1,1,1,1};
static int BaseRDelayCounts[NUM_CUBES] = {1,1,1,1,1,1,1,1,1,1,1};
static int InitMDelayCounts[NUM_CUBES] = {1,1,1,1,1,1,1,1,1,1,1};
static int BaseMDelayCounts[NUM_CUBES] = {1,1,1,1,1,1,1,1,1,1,1};
void InitializeCubes()
{
int i, j, k;
PObject *WorkingCube;
for (i=0; i<NUM_CUBES; i++) {
if ((WorkingCube = malloc(sizeof(PObject))) == NULL) {
printf("Couldn't get memory\n"); exit(1); }
WorkingCube->DrawFunc = DrawPObject;
WorkingCube->RecalcFunc = XformAndProjectPObject;
WorkingCube->MoveFunc = RotateAndMovePObject;
WorkingCube->RecalcXform = 1;
for (k=0; k<2; k++) {
WorkingCube->EraseRect[k].Left =
WorkingCube->EraseRect[k].Top = 0x7FFF;
WorkingCube->EraseRect[k].Right = 0;
WorkingCube->EraseRect[k].Bottom = 0;
}
WorkingCube->RDelayCount = InitRDelayCounts[i];
WorkingCube->RDelayCountBase = BaseRDelayCounts[i];
WorkingCube->MDelayCount = InitMDelayCounts[i];
WorkingCube->MDelayCountBase = BaseMDelayCounts[i];
/* Set the object->world xform to none */
for (j=0; j<3; j++)
for (k=0; k<4; k++)
WorkingCube->XformToWorld[j][k] = INT_TO_FIXED(0);
WorkingCube->XformToWorld[0][0] =
WorkingCube->XformToWorld[1][1] =
WorkingCube->XformToWorld[2][2] = INT_TO_FIXED(1);
/* Set the initial location */
for (j=0; j<3; j++) {
WorkingCube->XformToWorld[j][3] =
INT_TO_FIXED(CubeStartCoords[i][j]);
}
/* Initial center coordinates */
WorkingCube->CenterInView.X = WorkingCube->XformToWorld[0][3];
WorkingCube->CenterInView.Y = WorkingCube->XformToWorld[1][3];
WorkingCube->CenterInView.Z = WorkingCube->XformToWorld[2][3];
WorkingCube->NumVerts = NUM_CUBE_VERTS;
WorkingCube->VertexList = CubeVerts;
WorkingCube->NumFaces = NUM_CUBE_FACES;
WorkingCube->Rotate = InitialRotate[i];
WorkingCube->Move.MoveX = INT_TO_FIXED(InitialMove[i].MoveX);
WorkingCube->Move.MoveY = INT_TO_FIXED(InitialMove[i].MoveY);
WorkingCube->Move.MoveZ = INT_TO_FIXED(InitialMove[i].MoveZ);
WorkingCube->Move.MinX = INT_TO_FIXED(InitialMove[i].MinX);
WorkingCube->Move.MinY = INT_TO_FIXED(InitialMove[i].MinY);
WorkingCube->Move.MinZ = INT_TO_FIXED(InitialMove[i].MinZ);
WorkingCube->Move.MaxX = INT_TO_FIXED(InitialMove[i].MaxX);
WorkingCube->Move.MaxY = INT_TO_FIXED(InitialMove[i].MaxY);
WorkingCube->Move.MaxZ = INT_TO_FIXED(InitialMove[i].MaxZ);
if ((WorkingCube->XformedVertexList =
malloc(NUM_CUBE_VERTS*sizeof(Point3))) == NULL) {
printf("Couldn't get memory\n"); exit(1); }
if ((WorkingCube->ProjectedVertexList =
malloc(NUM_CUBE_VERTS*sizeof(Point3))) == NULL) {
printf("Couldn't get memory\n"); exit(1); }
if ((WorkingCube->ScreenVertexList =
malloc(NUM_CUBE_VERTS*sizeof(Point))) == NULL) {
printf("Couldn't get memory\n"); exit(1); }
if ((WorkingCube->FaceList =
malloc(NUM_CUBE_FACES*sizeof(Face))) == NULL) {
printf("Couldn't get memory\n"); exit(1); }
/* Initialize the faces */
for (j=0; j<NUM_CUBE_FACES; j++) {
WorkingCube->FaceList[j].VertNums = VertNumList[j];
WorkingCube->FaceList[j].NumVerts = VertsInFace[j];
WorkingCube->FaceList[j].Color = Colors[i][j];
}
AddObject((Object *)WorkingCube);
}
}